package com.neusoft.service.impl;

import com.neusoft.mapper.FoodMapper;
import com.neusoft.po.Food;
import com.neusoft.service.FoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RefreshScope
public class FoodServiceImpl implements FoodService {

	@Value("${learning.maskImg}")
	private boolean mask;

	@Autowired
	private FoodMapper foodMapper;

	@Override
	public List<Food> listFoodByBusinessId(Integer businessId) {
		List<Food> foodList = foodMapper.listFoodByBusinessId(businessId);
		System.out.println(mask);
		if(mask){
			for(Food food : foodList){
				food.setFoodImg("masked");
			}
		}
		return foodList;
	}

	@Override
	public int updateFood(Food food){
		return foodMapper.updateFood(food);
	}

	@Override
	public Food getFoodById(Integer foodId){
		Food food = foodMapper.getFoodById(foodId);
		if(mask){
			food.setFoodImg("masked");
		}
		return food;
	}

	@Override
	public int deleteFoodById(Integer BusinessId, Integer foodId) {
		return foodMapper.deleteFoodById(BusinessId, foodId);
	}

	@Override
	public int updateFoodById(Food food) {
		return foodMapper.updateFoodById(food);
	}
}
